// AlarmAnimationWnd.cpp : implementation file
//

#include "stdafx.h"
#include "kwclientcore.h"
#include "AlarmAnimationWnd.h"
#include "MainPanel.h"
#include "ClientConfiguration.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAlarmAnimationWnd

CAlarmAnimationWnd::CAlarmAnimationWnd():
m_strCoalMineName(),
m_strMonUnitId(),
m_timeStateChange()
{
  m_pFont = new CFont;
  LOGFONT lf;
  ZeroMemory(&lf, sizeof(LOGFONT));
  lf.lfHeight = -11;
  strcpy(lf.lfFaceName, "Tahoma");
  m_pFont->CreateFontIndirect(&lf);
}

CAlarmAnimationWnd::~CAlarmAnimationWnd()
{
  delete m_pFont;
}


BEGIN_MESSAGE_MAP(CAlarmAnimationWnd, CWnd)
	//{{AFX_MSG_MAP(CAlarmAnimationWnd)
	ON_WM_CREATE()
	ON_WM_LBUTTONDOWN()
	ON_WM_DESTROY()
	ON_WM_LBUTTONDBLCLK()
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CAlarmAnimationWnd message handlers

bool CAlarmAnimationWnd::Create(const CRect& rect, CWnd * pParentWnd)
{
  return CWnd::CreateEx(WS_EX_TOPMOST | WS_EX_CLIENTEDGE | WS_EX_TOOLWINDOW , 
                        AfxRegisterWndClass(CS_DBLCLKS, LoadCursor(NULL, IDC_ARROW)), 
                        "AlarmAnimationWnd", 
                        WS_POPUP | WS_BORDER,
                        rect, 
                        NULL,
                        0);
}

int CAlarmAnimationWnd::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CWnd::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// TODO: Add your specialized creation code here
  m_animAlarm.Create(WS_CHILD | WS_VISIBLE | WS_DISABLED | ACS_TRANSPARENT | ACS_AUTOPLAY, CRect(0, -2, 32, 32), this, 0);
  m_animAlarm.Open(IDR_AVI_ALARM);

	return 0;
}

void CAlarmAnimationWnd::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	SendMessage(WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM(point.x, point.y));

	CWnd::OnLButtonDown(nFlags, point);
}

void CAlarmAnimationWnd::OnDestroy() 
{
	CRect rect;
  GetWindowRect(&rect);
  ClientConfiguration::Instance()->m_ptAlarmAnimWndTopLeft = rect.TopLeft();
  
  CWnd::OnDestroy();
	
	// TODO: Add your message handler code here
	
}

void CAlarmAnimationWnd::OnLButtonDblClk(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	g_pMainPanel->OpenAlarmDataPanel();
  ShowWindow(SW_HIDE);

	CWnd::OnLButtonDblClk(nFlags, point);
}

void CAlarmAnimationWnd::PostNcDestroy() 
{
	// TODO: Add your specialized code here and/or call the base class
	delete this;

	CWnd::PostNcDestroy();
}

void CAlarmAnimationWnd::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
  CRect rect;
  GetClientRect(&rect);
	dc.FillSolidRect(&rect, RGB(0, 0, 0));

  CFont * pOldFont = dc.SelectObject(m_pFont);
  COLORREF crOldText = dc.SetTextColor(RGB(255, 255, 0));
  
  CString strTemp = m_strCoalMineName + " ";
  strTemp += m_strMonUnitId;
  dc.TextOut(33, 0, strTemp);
  dc.TextOut(33, 14, m_timeStateChange.Format("%d-%H:%M:%S"));
  dc.SetTextColor(crOldText);
  dc.SelectObject(pOldFont);

	// Do not call CWnd::OnPaint() for painting messages
}
